<!DOCTYPE html>
<html lang="en">

<head>
    <title>品学联萌</title>
    <#include "/pxlm/app/product/components/meta.html" />
    <#include "/pxlm/app/product/components/stylesheets.html" />
    <link rel="stylesheet" href="/pxlm/app/product/stylesheets/confirm.css?v=1">
</head>

<body>
    <div id="app">
        <header data-am-widget="header" class="am-header am-header-default am-header-fixed" style="background:url('/pxlm/img/pxlmappbanner.png') no-repeat center">
            <h1 class="am-header-title">订单信息</h1>
        </header>
        <div class="majors-list" v-if="cart && cart.length > 0">
            <div class="majors-item" v-for="(item, index) in cart" :key="index">
                <div class="major-content">
                    <div class="major-title">{{ item.title }} <span style="color: red;">￥{{ item.price }}</span></div>
                    <div class="major-subtitle">{{ item.formatTitle }}</div>
                </div>
            </div>
            <div class="total">总价：<span style="color: red;">￥{{ total }}</span></div>
        </div>
        <div class="buttons">
            <div class="pay-btn" @click="goPay">去支付</div>
        </div>
    </div>
    <#include "/pxlm/app/product/components/scripts.html" />
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                cart: [],
                total: 0
            }
        },
        mounted: function() {
            this.init();
        },
        methods: {
            init() {
                var cart = sessionStorage.getItem("cart");
                console.log(cart);
                this.cart = JSON.parse(cart);
                console.log(this.cart);
                var total = 0;
                for (var i = 0; i < this.cart.length; i ++) {
                    total += Number(this.cart[i].price);
                }
                this.total = total;
            },
            goPay() {
                var url = '${host!}/pxlm/app/product/api/pay';
                var params = {
                    cart: JSON.stringify(this.cart)
                };
                var success = res => {
                    console.log(res);
                    window.location.href = '${host!}' + res.info;
                }
                var fail = res => {
                    console.log(res);
                }
                var complete = () => {}
                request(url, params, success, fail, complete);
            }
        }
    })
    </script>
</body>

</html>